package o;

import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.purchasehistory.api.bean.PurchaseInfoBean;
import com.huawei.appmarket.service.pay.drm.bean.DrmCacheInfo;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class ecq {
    private static ArrayList<DrmCacheInfo> ˋ() {
        return (ArrayList) new cfp(epp.ॱ(".DrmSignData")).ˎ();
    }

    private static void ˊ(ArrayList<DrmCacheInfo> arrayList) {
        new cfp(epp.ॱ(".DrmSignData")).ˎ(arrayList);
    }

    public static void ॱ(DrmCacheInfo drmCacheInfo) {
        if (drmCacheInfo == null) {
            Logger.e("DrmSignDataProvider", "saveAndupdate info is null!");
            return;
        }
        String userId = drmCacheInfo.getUserId();
        String pkgName = drmCacheInfo.getPkgName();
        String developerId = drmCacheInfo.getDeveloperId();
        if (dof.ˋ(userId) || dof.ˋ(pkgName) || dof.ˋ(developerId)) {
            Logger.e("DrmSignDataProvider", "saveAndupdate param is not valid!");
            return;
        }
        ArrayList ˋ = ˋ();
        if (CollectCheck.isEmpty((List) ˋ)) {
            ˋ = new ArrayList();
        } else {
            DrmCacheInfo ˏ = ˏ(ˋ, userId, pkgName, developerId);
            if (ˏ != null) {
                ˋ.remove(ˏ);
            }
        }
        ˋ.add(drmCacheInfo);
        ˊ(ˋ);
        Logger.ˎ("DrmSignDataProvider", "saveAndupdate info end.");
    }

    public static void ˋ(String str, String str2, String str3) {
        ArrayList ˋ = ˋ();
        DrmCacheInfo ˏ = ˏ(ˋ, str, str2, str3);
        if (ˏ != null) {
            ˋ.remove(ˏ);
            ˊ(ˋ);
        }
    }

    private static DrmCacheInfo ˏ(ArrayList<DrmCacheInfo> arrayList, String str, String str2, String str3) {
        if (CollectCheck.isEmpty((List) arrayList)) {
            return null;
        }
        DrmCacheInfo drmCacheInfo;
        String ˋ = cev.ˋ(str);
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            drmCacheInfo = (DrmCacheInfo) it.next();
            String userId = drmCacheInfo.getUserId();
            String pkgName = drmCacheInfo.getPkgName();
            String developerId = drmCacheInfo.getDeveloperId();
            if (ˋ.equals(userId) && str2.equals(pkgName) && str3.equals(developerId)) {
                break;
            }
        }
        drmCacheInfo = null;
        return drmCacheInfo;
    }

    public static void ˎ(List<PurchaseInfoBean> list) {
        if (!CollectCheck.isEmpty((List) list)) {
            String userId = UserSession.getInstance().getUserId();
            if (!dof.ˋ(userId)) {
                ArrayList ˋ = ˋ();
                if (!CollectCheck.isEmpty((List) ˋ)) {
                    String ˋ2 = cev.ˋ(userId);
                    Iterator it = ˋ.iterator();
                    while (it.hasNext()) {
                        DrmCacheInfo drmCacheInfo = (DrmCacheInfo) it.next();
                        if (ˋ2.equals(drmCacheInfo.getUserId()) && !ˏ(list, drmCacheInfo.getPkgName())) {
                            it.remove();
                        }
                    }
                    ˊ(ˋ);
                }
            }
        }
    }

    private static boolean ˏ(List<PurchaseInfoBean> list, String str) {
        for (PurchaseInfoBean ॱ : list) {
            String ॱ2 = ॱ.ॱ();
            if (!dof.ˋ(ॱ2) && ॱ2.equals(str)) {
                return true;
            }
        }
        return false;
    }

    public static DrmCacheInfo ˊ(String str, String str2, String str3) {
        if (!dof.ˋ(str) && !dof.ˋ(str2) && !dof.ˋ(str3)) {
            return ˏ(ˋ(), str, str2, str3);
        }
        Logger.e("DrmSignDataProvider", "getItemByCondition param is not valid!");
        return null;
    }

    public static Map ˊ(DrmCacheInfo drmCacheInfo) throws UnsupportedEncodingException {
        Map hashMap = new HashMap();
        hashMap.put("rtnCode", "0");
        hashMap.put("ts", drmCacheInfo.getTs());
        List signList = drmCacheInfo.getSignList();
        if (!CollectCheck.isEmpty(signList)) {
            List arrayList = new ArrayList();
            Iterator it = signList.iterator();
            while (it.hasNext()) {
                Map map = (Map) it.next();
                String ˏ = eux.ˏ((String) map.get("signItem"), ecp.ˏ().ˋ().getBytes("UTF-8"), dnk.ˎ(drmCacheInfo.getIv()));
                Map hashMap2 = new HashMap();
                if (ˏ == null) {
                    Logger.ˎ("DrmSignDataProvider", "AESBaseDecrypt fail sign == null");
                    ˋ(drmCacheInfo.getUserId(), drmCacheInfo.getPkgName(), drmCacheInfo.getDeveloperId());
                    return null;
                }
                hashMap2.put("signItem", ˏ);
                hashMap2.put("payDeviceId", map.get("payDeviceId"));
                arrayList.add(hashMap2);
            }
            hashMap.put("signList", arrayList);
        }
        hashMap.put("appstore_version", ecs.ʽ());
        return hashMap;
    }
}
